package hivemq.config;

import com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3Publish;

import java.nio.charset.StandardCharsets;
import java.util.function.Consumer;

/**
 * @Author zhenyu
 * @desc
 * @Date 2022/10/11 16:27
 * @Version 1.0
 */
public class PushCallBack implements Consumer<Mqtt3Publish>{

  /**
   * 接收到消息时，调用（消费者/订阅者）
   * @param mqtt3Publish
   */
  @Override
  public void accept(Mqtt3Publish mqtt3Publish) {
    System.out.println("---------------------------");
    System.out.println("接收到的主题为：" + mqtt3Publish.getTopic());
    System.out.println("接收到的消息为：" + new String(mqtt3Publish.getPayloadAsBytes(), StandardCharsets.UTF_8));
    System.out.println("接收到的Qos为："  + mqtt3Publish.getQos());

  }

}